
(function($) {
    function Slide(element,options){
        this.element=$(element);
        this.options=options;
        this.sub=this.element.find('sub');        //向左箭头
        this.sup=this.element.find('sup');        //向右箭头
        this.cont=this.element.find('.content');  //文档内容
        this.left=0;
        this.width=this.cont.find('a').outerWidth(true)*this.cont.children(true).length-900
        this.sub.click($.proxy(function(){this.scrollleft(5)},this));
        this.sup.click($.proxy(function(){this.scrollright(5)},this));
    }
    Slide.prototype={
        constructor:Slide,
        scrollleft:function(n){
            var width=this.cont.find('a').outerWidth(true)
            var that=this
            /*---------------------
             动画回调函数 
            ----------------------*/
            function change(){
                var ses=that.cont.children().slice(0,n)
                ses.remove()
                ses.appendTo(that.cont)
                that.cont.css({left:0})
            }
            this.cont.animate({left:-n*width},800,change)
        },
        scrollright:function(n){
            var width=this.cont.find('a').outerWidth(true)
            var that=this
            var length=that.cont.children().length
            var ses=this.cont.children().slice(length-n,length)
            ses.remove()
            var div=$('<div>')
            ses.appendTo(div)
            div.css({position:'absolute',left:-n*width})
            div.prependTo(this.cont)
            //console.log(div)
            /*---------------------
             动画回调函数 
            ----------------------*/
            function change(){ 
                that.cont.css({left:'0px'})
                div.remove()
                ses.prependTo(that.cont)
                console.log(ses)      
            }
            this.cont.animate({left:n*width},800,change)
        }
    }
  /*---------------------
   bridge链接jquery
  ---------------------*/
    $.fn.slide=function(options){
        return this.each(function () {
            var $this = $(this);
            var  data = $this.data('slide')
            if (!data) $this.data('slide', (data = new Slide(this,options)));
            if (typeof options == 'string') data[options].call($this);
        })
    }
// 闭包结束
})(jQuery);